﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using CCWin.SkinControl;
using CCWin.SkinClass;
using GroupChat2013.Entity;
using GroupChat2013.Common;

namespace GroupChat2013.Main.Controls
{
    public partial class ButtonEx : UserControl
    {
        /// <summary>
        /// 设置名称
        /// </summary>
        public string ButtonName
        {
            set { this.btnSend.Name = value; }
        }

        /// <summary>
        /// 聊天配置
        /// </summary>
        public ChatConfigInfo configInfo;

        public ButtonEx()
        {
            InitializeComponent();

            this.tsiCtrlEnterSend.Click += new EventHandler(tsiCtrlEnterSend_Click);
            this.tsiEnterSend.Click += new EventHandler(tsiEnterSend_Click);
            this.tsiAltSSend.Click += new EventHandler(tsiAltSSend_Click);

            this.btnSend.Click+=new EventHandler(btnSend_Click);

            btnSendMenu.Click+=new EventHandler(btnSendMenu_Click);
            SendMenu.Closing+=new ToolStripDropDownClosingEventHandler(SendMenu_Closing);
        }

        /// <summary>
        /// 点击按钮事件
        /// </summary>
        public event EventHandler ButtonClick;

        public SendMode SendMode
        {
            get
            {
                if (tsiEnterSend.Checked)
                    return SendMode.ENTER;
                if (tsiCtrlEnterSend.Checked)
                    return SendMode.CTRLENTER;
                if (tsiAltSSend.Checked)
                    return SendMode.ALTS;

                return SendMode.CTRLENTER;
            }
            set
            {
                if (SendMode.ENTER == (SendMode)value)
                    tsiEnterSend_Click(tsiEnterSend, null);
                else if (SendMode.CTRLENTER == (SendMode)value)
                    tsiCtrlEnterSend_Click(tsiCtrlEnterSend, null);
                else
                    tsiAltSSend_Click(tsiAltSSend, null);

                //m_BehaviorConfig.SendMode = (int)value;
            }
        }

        #region 窗体事件

        /// <summary>
        /// 发送
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSend_Click(object sender, EventArgs e)
        {
            if (ButtonClick != null)
                ButtonClick(sender, e);
        }

        /// <summary>
        /// 按Enter发送
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsiEnterSend_Click(object sender, EventArgs e)
        {
            tsiEnterSend.Checked = true;
            tsiCtrlEnterSend.Checked = false;
            tsiAltSSend.Checked = false;

            if (configInfo != null)
                configInfo.SendMode = (int)SendMode;
        }

        /// <summary>
        /// 按Ctrl+Enter发送
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsiCtrlEnterSend_Click(object sender, EventArgs e)
        {
            tsiEnterSend.Checked = false;
            tsiCtrlEnterSend.Checked = true;
            tsiAltSSend.Checked = false;

            if (configInfo != null)
                configInfo.SendMode = (int)SendMode;
        }

        /// <summary>
        /// 按Alt+S发送
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsiAltSSend_Click(object sender, EventArgs e)
        {
            tsiEnterSend.Checked = false;
            tsiCtrlEnterSend.Checked = false;
            tsiAltSSend.Checked = true;

            if (configInfo != null)
                configInfo.SendMode = (int)SendMode;
        }

        //发送键更多选择
        private void btnSendMenu_Click(object sender, EventArgs e)
        {
            btnSendMenu.StopState = StopStates.Pressed;
            SendMenu.Show(btnSendMenu, new Point(0, btnSendMenu.Height + 5));
        }

        //发送键更多选择菜单关闭时
        private void SendMenu_Closing(object sender, ToolStripDropDownClosingEventArgs e)
        {
            btnSendMenu.StopState = StopStates.NoStop;
            btnSendMenu.ControlState = ControlState.Normal;
        }

        #endregion
    }
}
